package cn.tedu.property_management_system.controller;


import cn.tedu.property_management_system.entity.Building;
import cn.tedu.property_management_system.service.IBuildingService;
import cn.tedu.property_management_system.utils.JsonPage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/building")
public class BuildingController {
    @Autowired
    IBuildingService service;

    @RequestMapping("/search/select")
    public List<Building> select(@RequestBody Building building) {

        return service.select(building);
    }

    @RequestMapping("/add/insert")
    public void insert(@RequestBody Building building) {

        service.insert(building);
    }

    @RequestMapping("/list/select")
    public List<Building> list() {
        return service.list();
    }

    @RequestMapping("/edit/select")
    public Building editSelect(@RequestBody Building building) {
        return service.editSelect(building);
    }

    @RequestMapping("/edit/update")
    public void update(@RequestBody Building building) {

        service.update(building);

    }

    @RequestMapping("/row/delete")
    public void delete(@RequestBody Building building) {

        service.delete(building);
    }

    @RequestMapping("/rows/delete")
    public int deletes(@RequestBody List<Building> list) {

        return service.deletes(list);
    }

    @RequestMapping("/floor/select")
    public List<String> floor() {

        return service.floor();
    }

    @GetMapping("/get/page/{pageSize}/{pageIndex}")
    public JsonPage<Building> getPage(@PathVariable("pageSize") Integer pageSize,@PathVariable("pageIndex") Integer pageIndex) {
        log.debug(pageSize+"-----"+pageIndex);
        JsonPage<Building> buildingJsonPage = service.pageSelect(pageSize, pageIndex);
        return buildingJsonPage;
    }
}
